//
//  LoginViewController.m
//  XiXi
//
//  Created by HawkingWang on 16/9/29.
//  Copyright © 2016年 xi-xi.cc. All rights reserved.
//

#import "LoginViewController.h"
#import "WXApi.h"//微信Api

#import "TabBarController.h"

@interface LoginViewController () <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UITextField *managerName;
@property (weak, nonatomic) IBOutlet UITextField *managerPsd;
@property (weak, nonatomic) IBOutlet UIButton *wechatLoginBtn;
@property (weak, nonatomic) IBOutlet UILabel *label;

//@property (nonatomic, strong) UITextField *managerName;
//@property (nonatomic, strong) UITextField *managerPsd;



@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setLayer];

}

- (void)setLayer{
    _loginBtn.layer.cornerRadius = 4;
    _loginBtn.layer.masksToBounds = YES;
    
    _wechatLoginBtn.layer.masksToBounds = YES;
    _wechatLoginBtn.layer.cornerRadius = 22;
    _wechatLoginBtn.layer.borderWidth = 0.5;
    _wechatLoginBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    
    _label.layer.masksToBounds = YES;
    _label.layer.cornerRadius = 2;
    _label.layer.borderWidth = 0.5;
    _label.layer.borderColor = [UIColor whiteColor].CGColor;
    
    _managerName.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入管理员账号" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
    _managerName.delegate = self;
    _managerPsd.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入管理员密码" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
    _managerPsd.delegate = self;
}

- (IBAction)login:(id)sender {
    TabBarController *tab = [[TabBarController alloc] init];
    [self presentViewController:tab animated:NO completion:nil];
    //UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    //window.rootViewController = tab;
}
- (IBAction)wechatLogin:(id)sender {
    if ([WXApi isWXAppInstalled]) {
        SendAuthReq *req = [[SendAuthReq alloc] init];
        req.scope = @"snsapi_userinfo";
        req.state = @"123";
        [WXApi sendReq:req];
    }else{
        [self setupAlertController];
    }
}

//设置弹出提示语
- (void)setupAlertController{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请先安装微信客户端" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:nil];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_managerPsd resignFirstResponder];
    [_managerName resignFirstResponder];
}
@end
